import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path:'/',
    redirect: '/dashboard/index'
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/401',
    component:Layout,
    redirect: '/401/index',
    children: [{
      path: 'index',
      name: '401',
      component: () => import('@/views/401'),
      hidden: true
    }]
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }
]

export const asyncRoutes = [
  {
    path: '/dept',
    component: Layout,
    redirect: '/dept/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/dept/index'),
      meta: { title: '部门', icon: 'dept',id:'dept' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/user/index'),
      meta: { title: '员工', icon: 'el-icon-user-solid',id:'user' }
    }]
  },
  {
    path: '/acl',
    component: Layout,
    redirect: 'acl/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/acl/index'),
      meta: { title: '权限', icon: 'acl',id:'acl' }
    }]
  },
  {
    path: '/role',
    component: Layout,
    redirect: 'role/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/role/index'),
      meta: { title: '角色', icon: 'role' ,id:'role' }
    }]
  },
  {
    path: '/log',
    component: Layout,
    redirect: 'log/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/log/index'),
      meta: { title: '日志', icon: 'log' ,id:'log' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

